<template>
  <div class="announcement-detail-page">
    <div class="container">
      <div v-if="news" class="news-detail">
        <el-breadcrumb separator="/" class="breadcrumb">
          <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
          <el-breadcrumb-item :to="{ path: '/announcements' }">公告</el-breadcrumb-item>
          <el-breadcrumb-item>{{ news.title }}</el-breadcrumb-item>
        </el-breadcrumb>
        
        <el-card class="news-card">
          <div class="news-header">
            <h1>{{ news.title }}</h1>
            <div class="news-meta">
              <span class="date">{{ news.date }}</span>
              <el-tag type="success">公告</el-tag>
            </div>
          </div>
          
          <div class="news-image" v-if="news.imageUrl">
            <img :src="news.imageUrl" :alt="news.title" />
          </div>
          
          <div class="news-content">
            <p>{{ news.content }}</p>
          </div>
          
          <div class="news-footer">
            <el-button type="primary" @click="$router.push('/announcements')">
              返回公告列表
            </el-button>
          </div>
        </el-card>
      </div>
      
      <div v-else class="loading">
        <el-empty description="公告不存在或已被删除" />
        <el-button type="primary" @click="$router.push('/announcements')">
          返回公告列表
        </el-button>
      </div>
    </div>
  </div>
</template>

<script>
import { ref, onMounted } from 'vue'
import { useRoute } from 'vue-router'
import { getNewsData } from '../api/serverApi'

export default {
  name: 'AnnouncementDetailPage',
  setup() {
    const route = useRoute()
    const news = ref(null)

    onMounted(() => {
      const newsId = parseInt(route.params.id)
      const newsList = getNewsData()
      news.value = newsList.find(item => item.id === newsId)
    })

    return {
      news
    }
  }
}
</script>

<style scoped>
.announcement-detail-page {
  padding: 20px 0;
}

.breadcrumb {
  margin-bottom: 20px;
}

.news-card {
  max-width: 800px;
  margin: 0 auto;
}

.news-header {
  text-align: center;
  margin-bottom: 30px;
}

.news-header h1 {
  font-size: 2.5rem;
  color: #4CAF50;
  margin-bottom: 15px;
}

.news-meta {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 15px;
}

.date {
  color: #999;
  font-size: 1rem;
}

.news-image {
  margin: 30px 0;
  text-align: center;
}

.news-image img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.news-content {
  line-height: 1.8;
  font-size: 1.1rem;
  color: #333;
  margin: 30px 0;
}

.news-content p {
  margin-bottom: 20px;
}

.news-footer {
  text-align: center;
  margin-top: 40px;
  padding-top: 30px;
  border-top: 1px solid #eee;
}

.loading {
  text-align: center;
  padding: 60px 0;
}

@media (max-width: 768px) {
  .news-header h1 {
    font-size: 2rem;
  }
  
  .news-content {
    font-size: 1rem;
  }
}
</style> 